package main.java.content.player;

import main.java.auxiliary.Audio;
import main.java.base.BaseElement;
import main.java.base.IElement;

/**
 * @author 吴浩华 陈逸然 吴畏
 * @Description: 攻击火箭
 * @date 2021/6/10
 */
@IElement(
        leftImage = "LeftPlane.gif",
        rightImage = "RightPlane.gif",
        width = 50,
        height = 50)
public class Rocket extends BaseElement {

    private Player player;//拳头的y坐标始终要与玩家一致
    private int count;//计数

    public Rocket(Player player) {
        super(player.getX(), player.getY());
        this.direction = player.getDirection();
        float energy = player.fistSkill.getEnergy();
        this.xSpeed = 10;
        //this.xSpeed = energy > 5555? 5555 : energy;
        this.player = player;
        Audio.PlayerFist.play();
        this.y = player.getY();//获取当前y坐标放大炮
    }

    @Override
    public void action() {

        if (count == 0) {
            this.x = player.getX();
        }
        else if (count < 10) { //发射
            this.x += direction.right() ? xSpeed + player.getxSpeed() : -xSpeed - player.getxSpeed();
        }
        else { //继续飞行
            this.x += direction.right() ? xSpeed + player.getxSpeed() : -xSpeed - player.getxSpeed();
        }
        count++;
    }

    //@Override
    /**public boolean remove(Player player) {
        if (count > 18) {
            return true;
        }
        //与玩家方向相反时消除
        if (!direction.equals(player.getDirection())) {
            return true;
        }
        //如果面朝右边，则拳头小于玩家坐标时移除
        if (direction.right()) {
            return this.x < player.getX() - player.getxSpeed() - 1;
        } else {
            return this.x > player.getX() + player.getxSpeed() + 1;
        }
    }**/

    public int getAggressivity() {
        return this.player.playerState.aggressivity.getValue();
    }
}
